package exercise;

import java.util.Scanner;

//优化Test1代码
//自动抽取方法快捷键 ctrl + alt + M
public class Test2 {
    public static void main(String[] args) {
        //键盘录入机票原价、月份、头等舱或经济舱
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入机票原价：");
        int ticket = sc.nextInt();
        System.out.println("请输入月份：");
        int month = sc.nextInt();
        System.out.println("请输入购买仓位 0 头等舱 1 经济舱：");
        int seat = sc.nextInt();
        //判断月份是否淡旺季
        if (month >= 5 && month <= 10) { //旺季
          ticket= getPrice(ticket,seat,0.9,0.85);
            //淡季
        } else if ((month >= 1 && month <= 4) || (month >= 11 && month <= 12)) {
            ticket= getPrice(ticket,seat,0.7,0.65);
        } else {
            System.out.println("没有这个月份");
        }
        System.out.println(ticket);
    }
    public static int getPrice(int ticket,int seat,double v0,double v1) {
        if (seat == 0) { //头等舱
            ticket = (int) (ticket * v0);
        } else if (seat == 0) { //经济舱
            ticket = (int) (ticket * v1);
        } else {
            System.out.println("没有这个舱位");
        }
        return ticket;
    }
}
